use std::env;
use std::process;
pub fn atoi(s: &str) -> i32 {
    let mut result = 0;
    let mut sign = 1;
    let mut s = s.trim_start();
    if let Some(first_char) = s.chars().next() {
        if first_char == '+' {
            s = &s[1..];
        } else if first_char == '-' {
            sign = -1;
            s = &s[1..];
        }
    }
    for c in s.chars() {
        if let Some(digit) = c.to_digit(10) {
            if result > i32::MAX as u32 / 10 || (result == i32::MAX as u32 / 10 && digit > 7) {
                return if sign == 1 { i32::MAX } else { i32::MIN };
            }
            result = result * 10 + digit as u32;
        } else {
            break;
        }
    }
    sign * result as i32
}
pub fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        eprintln!("Usage: {} <number>", args[0]);
        process::exit(1);
    }
    let value = atoi(&args[1]);
    println!("Parsed integer: {}", value);
}
